package machinery.decorator;

import machinery.Machinery;
import java.util.Map;

/**
 * 自动灌溉系统装饰器：给农机添加智能灌溉功能
 */
public class AutoIrrigationDecorator extends MachineryDecorator {
    private int waterLevel;
    
    public AutoIrrigationDecorator(Machinery decoratedMachinery) {
        super(decoratedMachinery);
        this.waterLevel = 100; // 初始水量100%
        System.out.println("为" + decoratedMachinery.getName() + "安装自动灌溉系统");
    }
    
    @Override
    protected void additionalUpdate(Map<String, Object> environmentData) {
        System.out.println(getName() + " 自动灌溉系统分析土壤数据...");
        
        if (environmentData.containsKey("soilMoisture")) {
            Integer moisture = (Integer) environmentData.get("soilMoisture");
            if (moisture < 30 && waterLevel > 0) {
                System.out.println(getName() + " 自动灌溉系统: 检测到土壤干旱(" + moisture + "%)，启动智能灌溉");
                irrigate();
            }
        }
    }
    
    @Override
    public String getName() {
        return decoratedMachinery.getName() + "[智能灌溉]";
    }
    
    // 额外方法：灌溉
    public void irrigate() {
        if (waterLevel > 0) {
            System.out.println(getName() + " 启动智能灌溉...");
            System.out.println("  - 根据土壤墒情调整灌溉量");
            System.out.println("  - 精准定位灌溉区域");
            waterLevel -= 10;
            System.out.println("  - 剩余水量: " + waterLevel + "%");
        } else {
            System.out.println(getName() + " 水箱已空，需要补充水源");
        }
    }
    
    // 额外方法：补充水源
    public void refillWater() {
        System.out.println(getName() + " 正在补充水源...");
        waterLevel = 100;
        System.out.println("水箱已补满: " + waterLevel + "%");
    }
} 